<?php 
// +----------------------------------------------------------------------
// | Item        短信模板模型
// +----------------------------------------------------------------------
// | Copyright
// +----------------------------------------------------------------------
// | Versions
// +----------------------------------------------------------------------
// | Author       YanHao
// +----------------------------------------------------------------------
// | Date         2017-07-12
// +----------------------------------------------------------------------

namespace app\admin\model;

use think\Validate;

class SnsTemplate extends Base 
{ 
    /**
     * 验证规则
     * @var [type]
     */
    protected $rules = [
        'scene|模板场景'         => 'require|in:1,2,3,4,5',
        'name|模板名称'          => 'require|max:12',
        'content|模板内容'       => 'require|max:255',
        'update_at|模板更新时间' => 'require|date'
    ];
    /**
     * 验证场景
     * @var array
     */
    protected $scene = [
        'add'    => ['scene', 'name', 'content'],
        'update' => ['scene', 'name', 'content', 'update_at'] 
    ];
    /**
     * 获取模板所有信息
     * @Author  YanHao
     * @Date    2017-07-13
     * @version [version]
     * @param   array      $where    [description]
     * @param   [type]     $pageSize [description]
     * @param   array      $config   [description]
     * @return  [type]               [description]
     */
    public function getAllTemplate(array $where, $pageSize, array $config)
    {
        return $this->where($where)->field(true)->order('create_at desc')->paginate($pageSize, false, $config);
    }
    /**
     * 新增、修改模板
     * @Author  YanHao
     * @Date    2017-07-13
     * @version [version]
     * @param   array      $post [description]
     * @return  [type]           [description]
     */
    public function createTemplate(array $post)
    {

    }
    /**
     * 更改模板使用状态
     * @Author  YanHao
     * @Date    2017-07-13
     * @version [version]
     * @param   [type]     $value [description]
     * @param   [type]     $id    [description]
     * @return  [type]            [description]
     */
    public function changeStatus($value, $id)
    {
        $updateData = [
            'status' => $value,
            'update_at' => date("Y-m-d H:i:s")
        ];
        $handle = $this->isUpdate(true)->save($updateData, ['id' => $id]);
        return $handle ? ['code' => 1, 'msg' => '操作成功'] : ['code' => 0, 'msg' => '操作失败'];
    }
    

}